package com.yiyuan.system.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.yiyuan.common.base.BaseDao;
import com.yiyuan.system.dao.IOrgDao;
import com.yiyuan.system.model.Organ;

@Repository("orgDao")
public class OrgDaoHbImpl extends BaseDao implements IOrgDao {
	public void add(Organ organ) {
		this.getHibernateTemplate().save(organ);
	}

	@SuppressWarnings("unchecked")
	public List<Organ> findList() {
		Session session = this.getSession();
		Query query = session.createQuery("from Organ order by orgCode");		
		List<Organ> list = query.list();
		return list;
	}

	public int getPageCount() {
		Session session = this.getSession();
		Query query = session.createQuery("select count(*) from Organ ");
		int count = Integer.parseInt(query.uniqueResult().toString());
		return count;
	}

	public void update(Organ organ) {
		this.getHibernateTemplate().update(organ);
	}

	public Organ get(Integer orgId) {
		return (Organ) this.getHibernateTemplate().get(Organ.class, orgId);
	}

	public void delete(Organ organ) {
		this.getHibernateTemplate().delete(organ);
	}

	@SuppressWarnings("unchecked")
	public List<Organ> findSubList(String orgId) {
		Session session = this.getSession();
		Query query = session.createQuery("from Organ where orgPid=:orgPid");
		query.setInteger("orgPid", Integer.parseInt(orgId));
		List<Organ> list = query.list();
		return list;
	}

}
